<?php

namespace App\Http\Validators;

use Validator;

trait ValidatorTraits
{
    private $rules = [];
    private $msgs = [];

    public function __construct()
    {
        $this->rules();
        $this->msgs();
    }

    /**
     * 执行校验
     * @param $data
     * @return array
     */
    public function excute($data)
    {
        $validate = Validator::make($data, $this->rules, $this->msgs);
        if ($validate->fails()) {
            return ['status' => 0, 'msg' => $validate->errors()->first()];
        } else {
            return ['status' => 1];
        }
    }
}